<?php

if (!defined('DP_BASE_DIR')){
	die(MessageStatic::$notAccessMessage);
}

include DP_BASE_DIR .'/base/list/ArrayList.class.php';
include DP_BASE_DIR .'/base/db/DBConnection.class.php';
include DP_BASE_DIR .'/base/db/CommonDAO.class.php';
include DP_BASE_DIR .'/integration/to/LovTO.class.php';

require_once(DP_BASE_DIR .'/bootstrap.php');

include DP_BASE_DIR .'/integration/models/REQ_COMPETENCES_AIESEC.php';
include DP_BASE_DIR .'/integration/models/REQ_TP_ID.php';
include DP_BASE_DIR .'/integration/models/REQ_TP_LEVEL.php';
include DP_BASE_DIR .'/integration/models/REQ_TP_LANGUAJE.php';
include DP_BASE_DIR .'/integration/models/REQ_COMMON_U_PROG.php';
include DP_BASE_DIR .'/integration/models/REQ_SKILLS.php';
include DP_BASE_DIR .'/integration/models/REQ_FORM_BASE.php';
include DP_BASE_DIR .'/integration/models/REQ_LC.php';
include DP_BASE_DIR .'/integration/models/REQ_SEASON_REQ.php';
include DP_BASE_DIR .'/integration/models/REQ_SEMESTER.php';
include DP_BASE_DIR .'/integration/models/REQ_LC_UNIVERSITY.php';
include DP_BASE_DIR .'/integration/models/REQ_LC_UNIVERSITYTable.php';
include DP_BASE_DIR .'/integration/models/REQ_UNIVERSITY.php';
include DP_BASE_DIR .'/integration/models/REQ_FORM_ANSWER_ESP.php';
include DP_BASE_DIR .'/integration/models/REQ_FORM_COMP_SKILL.php';
include DP_BASE_DIR .'/integration/models/REQ_FORM_LANGUAJE_EXP.php';
include DP_BASE_DIR .'/integration/models/REQ_FORM_LIST_SKILL.php';
include DP_BASE_DIR .'/integration/models/REQ_FORM_WORK_EXP.php';
include DP_BASE_DIR .'/integration/models/REQ_FORM_LIST_COMP.php';


include DP_BASE_DIR .'/integration/roe/SelectCboROE.class.php';
include DP_BASE_DIR .'/integration/vo/SemesterVO.class.php';
include DP_BASE_DIR .'/integration/vo/MediaToKnowAIESECInfoVO.class.php';
include DP_BASE_DIR .'/integration/dao/SemesterDAO.class.php';

		


/**
 *
 * 
 * 
 * @author alvaroj
 *
 */
class RecruitmentMngr {

	
	/**
	 * 
	 * @return ArrayList SemesterVO.class
	 */
	public static function getNumberSemesterOfYear(){

		// create an instante of data base connection	
		$lst = new ArrayList();

		// TODO change with the component with information
		$lovTO = new LovTO();
		$lovTO->value = $lovTO->text = '2010 1';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->value = $lovTO->text = '2010 2';
		$lst->add($lovTO);
		
		$lovTO = new LovTO();
		$lovTO->value = $lovTO->text = '2011 1';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->value = $lovTO->text = '2011 2';
		$lst->add($lovTO);
		
		$lovTO = new LovTO();
		$lovTO->value = $lovTO->text = '2012 1';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->value = $lovTO->text = '2012 2';
		$lst->add($lovTO);
		
		$lovTO = new LovTO();
		$lovTO->value = $lovTO->text = '2013 1';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->value = $lovTO->text = '2013 2';
		$lst->add($lovTO);
		
		$lovTO = new LovTO();
		$lovTO->value = $lovTO->text = '2014 1';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->value = $lovTO->text = '2014 2';
		$lst->add($lovTO);
		
		$lovTO = new LovTO();
		$lovTO->value = $lovTO->text = '2015 1';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->value = $lovTO->text = '2015 2';
		$lst->add($lovTO);
		

		return $lst; 
	}
	
	/**
	 * 
	 * @return ArrayList SemesterVO.class
	 */
	public static function getYesNotinfo(){

		// create an instante of data base connection	
		$lst = new ArrayList();

		// TODO change with the component with information
		$lovTO = new LovTO();
		$lovTO->value = 1;
		$lovTO->text = 'YES';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->value = 0;
		$lovTO->text = 'NO';
		$lst->add($lovTO);

		return $lst; 
	}
	
	
	/**
	 * 
	 * @return ArrayList SemesterVO.class
	 */
	public static function getAllLC(){

		// create an instante of data base connection	
		$lst = new ArrayList();
		$lstTpId = Doctrine_Core::getTable('REQ_LC')->findAll(Doctrine_core::HYDRATE_RECORD);
		$tpLevel = new REQ_LC();
		foreach ($lstTpId as $tpLevel){
			$lovTO = new LovTO();
			$lovTO->value = $tpLevel->ID_REQ_LC;
			$lovTO->text = $tpLevel->NAME_P;
			//limit the opcion ALL LC
			if($lovTO->value != -1 ){
				$lst->add($lovTO);	
			}
		}
		return $lst; 
	}
	
	/**
	 * 
	 * @return ArrayList SemesterVO.class
	 */
	public static function getAllTypeOfID(){

		// create an instante of data base connection	
		$lst = new ArrayList();
		$lstTpId = Doctrine_Core::getTable('REQ_TP_ID')->findAll(Doctrine_core::HYDRATE_RECORD);
		$tpId = new REQ_TP_ID();
		foreach ($lstTpId as $tpId){
			$lovTO = new LovTO();
			$lovTO->value = $tpId->ID_REQ_TP_ID;
			$lovTO->text = $tpId->NAME_P;
			$lst->add($lovTO);
		}
		
		return $lst; 
	}

	/**
	 * 
	 * @return ArrayList SemesterVO.class
	 */
	public static function getAllUniverityByLC($idLC){
				
		$db=DBConnection::getInstance();
		$selectCboROE = new SelectCboROE($db);
		$lst = $selectCboROE->getValuesUniversityByLC($idLC);
		
		// add other option
		$lovTO = new LovTO();
		$lovTO->value = -1;
		$lovTO->text = 'OTHER';
		$lst->add($lovTO);
		
		return $lst; 
	}

	/**
	 * 
	 * @return ArrayList SemesterVO.class
	 */
	public static function getAllSemester(){
		// create an instante of data base connection	
		$lstReturn = new ArrayList();
		$db=DBConnection::getInstance();
		$semesterDAO = new SemesterDAO($db);
		$lst = $semesterDAO->getAll();
		$lovTO = new LovTO();
		while($lst->hasNext()){
			$semesterVO = $lst->next();
			$lovTO = new LovTO();
			$lovTO->value = $semesterVO->semester;
			$lovTO->text = $lovTO->name = $semesterVO->semester;
			$lstReturn->add($lovTO);	
		}
		return $lstReturn; 
	}
	/**
	 * 
	 * @return ArrayList SemesterVO.class
	 */
	public static function getLanguageLevel(){

		// create an instante of data base connection	
		$lst = new ArrayList();
		$lstTpId = Doctrine_Core::getTable('REQ_TP_LEVEL')->findAll(Doctrine_core::HYDRATE_RECORD);
		$tpLevel = new REQ_TP_LEVEL();
		foreach ($lstTpId as $tpLevel){
			$lovTO = new LovTO();
			$lovTO->value = $tpLevel->ID_REQ_TP_LEVEL;
			$lovTO->text = $tpLevel->NAME_P;
			$lst->add($lovTO);
		}
		
		return $lst; 
	}

	/**
	 * 
	 * @return ArrayList SemesterVO.class
	 */
	public static function getLanguage(){

		// create an instante of data base connection	
		$lst = new ArrayList();
		$lstTpId = Doctrine_Core::getTable('REQ_TP_LANGUAJE')->findAll(Doctrine_core::HYDRATE_RECORD);
		$tpLanguaje = new REQ_TP_LANGUAJE();
		foreach ($lstTpId as $tpLanguaje){
			$lovTO = new LovTO();
			$lovTO->value = $tpLanguaje->ID_REQ_TP_LANGUAJE;
			$lovTO->text = $tpLanguaje->NAME_P;
			$lst->add($lovTO);
		}
		
		return $lst; 
		
		
	}

	/**
	 * 
	 * @return ArrayList with information of carrer in colombia
	 */
	public static function getAllCarrer(){
		
		
		// create an instante of data base connection	
		$lst = new ArrayList();
		$lstCommon = Doctrine_Core::getTable('REQ_COMMON_U_PROG')->findAll(Doctrine_core::HYDRATE_RECORD);
		$tpUniversityProg = new REQ_COMMON_U_PROG();
		foreach ($lstCommon as $tpUniversityProg){
			$lovTO = new LovTO();
			$lovTO->value = $tpUniversityProg->ID_REQ_COMMON_U_PROG;
			$lovTO->text = $tpUniversityProg->NAME_P;
			if($lovTO->value != -1){
				$lst->add($lovTO);
			}
		}
		// add other option
		$lovTO = new LovTO();
		$lovTO->value = -1;
		$lovTO->text = 'OTHER';
		$lst->add($lovTO);
		
		return $lst; 
	}
	
/**
	 * 
	 * @return ArrayList with information of carrer in colombia
	 */
	public static function getDurationWorkMonth(){
		// create an instante of data base connection	
		$lst = new ArrayList();
				
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '0-2';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '2-8';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '8-more';
		$lst->add($lovTO);
		return $lst; 
	}
	
	
	
	/**
	 * 
	 * @return ArrayList with information of Hour
	 */
	public static function getAcademicHour(){
		// create an instante of data base connection	
		$lst = new ArrayList();		
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '01 - 05'; 
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '06 - 10';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '11 - 15';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '16 - 20';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '21 - 25';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '26 - 30';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '31 - 35';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '36 - 40';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '45 - 50';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '51 - 55';
		$lst->add($lovTO);
		return $lst; 
	}
	
/**
	 * 
	 * @return ArrayList with information of Hour
	 */
	public static function getAIESECHour(){
		// create an instante of data base connection	
		$lst = new ArrayList();		
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '01 - 05'; 
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '06 - 10';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '11 - 15';
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = '16 - 20';
		return $lst; 
	}
	
	/**
	 * 
	 * @return unknown_type
	 */
	public static function getProfesionalSkills(){

		// create an instante of data base connection	
		$lst = new ArrayList();
		$lstCommon = Doctrine_Core::getTable('REQ_SKILLS')->findAll(Doctrine_core::HYDRATE_RECORD);
		$tpSkills = new REQ_SKILLS();
		foreach ($lstCommon as $tpSkills){
			$lovTO = new LovTO();
			$lovTO->value = $tpSkills->ID_REQ_SKILLS;
			$lovTO->name = 'chkPSkill'.$tpSkills->ID_REQ_SKILLS;
			$lovTO->text = $tpSkills->NAME_P;
			$lst->add($lovTO);
		}
		
		return $lst; 
	}

	
	
	
	/**
	 * 
	 * @return unknown_type
	 */
	public static function getMediaToKnowAIESEC($Prefix){

		// create an instante of data base connection	
		$lst = new ArrayList();

		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = 'POSTERS';
		$lovTO->name = $Prefix.$lovTO->text;
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value = 'FRIENDS';
		$lovTO->name = $Prefix .$lovTO->text;
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value =  'FLYERS';
		$lovTO->name = $Prefix .$lovTO->text;
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value =  'RADIO';
		$lovTO->name = $Prefix .$lovTO->text;
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value =  'TV';
		$lovTO->name = $Prefix .$lovTO->text;
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value =  'TEACHERS';
		$lovTO->name = $Prefix .$lovTO->text;
		$lst->add($lovTO);
		$lovTO = new LovTO();
		$lovTO->text = $lovTO->value =  'EVENTS';
		$lovTO->name = $Prefix .$lovTO->text;
		$lst->add($lovTO);
		
		return $lst; 
	}
	
	
	/**
	 * 
	 * @return unknown_type
	 */
	public static function getAIESECCompetencesForChkBox($Prefix){
		// create an instante of data base connection	
		$lst = new ArrayList();
		$lstCommon = Doctrine_Core::getTable('REQ_COMPETENCES_AIESEC')->findAll(Doctrine_core::HYDRATE_RECORD);
		$tpComp = new REQ_COMMON_U_PROG();
		foreach ($lstCommon as $tpComp){
			$lovTO = new LovTO();
			$lovTO->value = $tpComp->ID_REQ_COMPETENCES_AIESEC;
			$lovTO->text = $tpComp->NAME_P;
			$lovTO->name = $Prefix.$lovTO->value;	
			$lst->add($lovTO);
		}
		
		return $lst; 
	}
	
	
	
	/**
	 * This function help to save in db all the information 
	 * 
	 * @param $objFormBase FormBaseTO obj of this class FormBaseTO
	 * @return state of save in data base
	 */
	public static function saveForm(FormBaseTO $objFormBase){
		
		/*
		 * save form base
		 */
		$reqFormBase = new REQ_FORM_BASE();
		
		// autoincrement
		//$reqFormBase->ID_REQ_FORM_BASE
		$reqFormBase->PING_ID = $objFormBase->stPingID;
		//TODO for the first version use the same season
        $reqFormBase->ID_REQ_SEASON_REQ = 1; 
        $reqFormBase->ID_REQ_LC = $objFormBase->intLCID;
        $reqFormBase->ID_REQ_TP_ID = $objFormBase->intIdTpID;
        $reqFormBase->NAME1= $objFormBase->stName1;
        $reqFormBase->NAME2= $objFormBase->stName2;
        $reqFormBase->LASTNAME1= $objFormBase->stLastName1;
        $reqFormBase->LASTNAME2= $objFormBase->stLastName2;
        $reqFormBase->EMAIL= $objFormBase->stEmail;
        $reqFormBase->ID= $objFormBase->intID;
        $reqFormBase->BIRTHDAY= $objFormBase->dateBirthday;
        $reqFormBase->FROMCITY= $objFormBase->stFrontCity;
        $reqFormBase->ADDRESPLACE= $objFormBase->stAddresPlace;
        $reqFormBase->PHONE= $objFormBase->stPhone;
        $reqFormBase->CELPHONE= $objFormBase->stCelPhone;
        $reqFormBase->ID_REQ_UNIVERSITY = $objFormBase->intIdUniversity;
        $reqFormBase->OTHER_U = $objFormBase->stOtherUniversity;
        $reqFormBase->ID_REQ_COMMON_U_PROG= $objFormBase->intIdCommonUniversityProgram;
        $reqFormBase->OTHER_U_PROG= $objFormBase->stOtherUniversityProgram;
        $reqFormBase->SEMESTER= $objFormBase->intIdSemester;
        $reqFormBase->ACADEMIC_HOUR = $objFormBase->stAcademicHour;
        $reqFormBase->AIESEC_HOUR= $objFormBase->stAIESECHour;
        
        $reqFormBase->INTERES_LIVE_X_EXP = $objFormBase->stInteresInLiveXExp;
        $reqFormBase->S_TO_LIVE_X_EXP = $objFormBase->stSemesterThatCouldBeLiveThisExp;
        $reqFormBase->DURATION_OF_X_EXP = $objFormBase->stDurationOfXExp;
        
        $stMediaToKnowAiesec = '|';
        $lstMedia = $objFormBase->lstMediaToKnowAIESEC;
       
        while($lstMedia->hasNext()){
        	$mediaToKnowAIESECInfoVO = $lstMedia->next();
        	$stMediaToKnowAiesec = $stMediaToKnowAiesec.$mediaToKnowAIESECInfoVO->stNameMedia . '|';
        }
        
        $reqFormBase->MEDIA_TO_KNOW_AIESEC = $stMediaToKnowAiesec;
        
        $reqFormBase->OTHER_M_TO_KNOW_AIESEC = $objFormBase->stOtherMediaToKnowAIESEC;
        $reqFormBase->WHY_DECIDE_APPLY = $objFormBase->stWhyDidYouDecideAplyToAIESEC;
        $reqFormBase->HOW_YOU_CONTRIBUTION = $objFormBase->stWhoDoYouThinkYouCouldContributeAIESEC;
        
        $reqFormBase->CREATION_DATE= date("Y-m-d");
        
        $reqFormBase->save();
        
        $lstWorkInfo =  $objFormBase->lstWorkInformation;
        $intCont = 1;
		while($lstWorkInfo->hasNext()){
        	$workInfoVO = $lstWorkInfo->next();
			$rEQ_FORM_WORK_EXP = new REQ_FORM_WORK_EXP();
			$rEQ_FORM_WORK_EXP->ID_REQ_FORM_BASE = $reqFormBase->ID_REQ_FORM_BASE;
			$rEQ_FORM_WORK_EXP->NAME_COMPANY = $workInfoVO->stNameCompany;
			$rEQ_FORM_WORK_EXP->DURATION_MONTH = $workInfoVO->stDurationMonth;
			$rEQ_FORM_WORK_EXP->RESPONSABILITIES = $workInfoVO->stResp;
			$rEQ_FORM_WORK_EXP->NUMBER = $intCont;
			$intCont = $intCont + 1 ;
			$rEQ_FORM_WORK_EXP->save();
			
        }
        
        
        $lstLanguageInfo = $objFormBase->lstlanguageInformation;
        $intCont = 1;
		while($lstLanguageInfo->hasNext()){
        	$languageInfoVO = $lstLanguageInfo->next();
        	$rEQ_FORM_LANGUAJE_EXP = new REQ_FORM_LANGUAJE_EXP();
			$rEQ_FORM_LANGUAJE_EXP->ID_REQ_FORM_BASE = $reqFormBase->ID_REQ_FORM_BASE;
			$rEQ_FORM_LANGUAJE_EXP->ID_REQ_TP_LANGUAJE = $languageInfoVO->intIdTpLang;
			$rEQ_FORM_LANGUAJE_EXP->ID_REQ_TP_LEVEL_READ = $languageInfoVO->intIdTpReading;
			$rEQ_FORM_LANGUAJE_EXP->ID_REQ_TP_LEVEL_WRITE = $languageInfoVO->intIdTpWriting;
			$rEQ_FORM_LANGUAJE_EXP->ID_REQ_TP_LEVEL_COMP = $languageInfoVO->intIdTpComprehension;
			$rEQ_FORM_LANGUAJE_EXP->NUMBER = $intCont;
			$intCont = $intCont + 1 ;
			$rEQ_FORM_LANGUAJE_EXP->save();
			
        }
        
        $lstProfesionalSkillsSelected = $objFormBase->lstSkillsToLikeDevelop;
        
		while($lstProfesionalSkillsSelected->hasNext()){
        	$profesionalSkillInfoVO = $lstProfesionalSkillsSelected->next();
        	$rEQ_FORM_LIST_SKILL = new REQ_FORM_LIST_SKILL();
			$rEQ_FORM_LIST_SKILL->ID_REQ_FORM_BASE = $reqFormBase->ID_REQ_FORM_BASE;
			$rEQ_FORM_LIST_SKILL->ID_REQ_SKILLS = $profesionalSkillInfoVO->intIdPSkill;
			$rEQ_FORM_LIST_SKILL->save();
        }
        
		$lstStrongCompSelected = $objFormBase->lstStrongCompetentes;
        
		while($lstStrongCompSelected->hasNext()){
        	$competenceInfoVO = $lstStrongCompSelected->next();
        	$rEQ_FORM_LIST_COMP = new REQ_FORM_LIST_COMP();
			$rEQ_FORM_LIST_COMP->ID_REQ_FORM_BASE = $reqFormBase->ID_REQ_FORM_BASE;
			$rEQ_FORM_LIST_COMP->ID_REQ_COMPETENCES_AIESEC = $competenceInfoVO->intIdCompetence;
			$rEQ_FORM_LIST_COMP->STRONG_WEAK = 'S';
			$rEQ_FORM_LIST_COMP->save();
        }
        
		$lstWeakCompSelected = $objFormBase->lstWeakCompetentes;
        
		while($lstWeakCompSelected->hasNext()){
        	$competenceInfoVO = $lstWeakCompSelected->next();
        	$rEQ_FORM_LIST_COMP = new REQ_FORM_LIST_COMP();
			$rEQ_FORM_LIST_COMP->ID_REQ_FORM_BASE = $reqFormBase->ID_REQ_FORM_BASE;
			$rEQ_FORM_LIST_COMP->ID_REQ_COMPETENCES_AIESEC = $competenceInfoVO->intIdCompetence;
			$rEQ_FORM_LIST_COMP->STRONG_WEAK = 'W';
			$rEQ_FORM_LIST_COMP->save();
        }
       
        
        require 'basicAppFinish.php';
        
	}


}
